# -*- coding:utf-8 -*-
from flask_marshmallow import Marshmallow
from marshmallow import fields, Schema


from models import Questions
from models import Answers

ma = Marshmallow()


class UserSchema(Schema):
    id = fields.Integer()
    name = fields.String()


class QuestionsSchema(ma.ModelSchema):
    user = fields.Nested(UserSchema)

    class Meta:
        model = Questions
        fields = ('id', 'title', 'descriptions', 'user', 'createTime')


class AnswersSchema(ma.ModelSchema):
    user = fields.Nested(UserSchema)

    class Meta:
        model = Answers
        fields = ('id', 'content', 'user', 'questions', 'createTime')


question_schema = QuestionsSchema()
questions_schema = QuestionsSchema(many=True)

answer_schema = AnswersSchema()
answers_schema = AnswersSchema(many=True)
